package pandora.apps.d3mob.view;

import pandora.apps.d3mob.MainLoop;
import android.os.AsyncTask;
import com.e3roid.drawable.tmx.TMXException;
import com.e3roid.drawable.tmx.TMXTiledMap;
import com.e3roid.drawable.tmx.TMXTiledMapLoader;
import com.e3roid.util.Debug;

public class MapLoader extends AsyncTask<Void,Integer,TMXTiledMap> {

	private String fileName;
	private MainLoop parent;
	
	public MapLoader(String TMXfileName, MainLoop parent) {
		this.fileName = TMXfileName;
		this.parent = parent;
	}
	
	@Override
	protected TMXTiledMap doInBackground(Void... params) {
		try {
			TMXTiledMapLoader mapLoader = new TMXTiledMapLoader();
			TMXTiledMap map = mapLoader.loadFromAsset(this.fileName, this.parent);
			return map;
		} catch (TMXException e) {
			Debug.e(e.getMessage());
		}
		return null;
	}

	@Override
	protected void onPostExecute(TMXTiledMap tmxTiledMap) {
	    parent.load(tmxTiledMap);
	}
	
	
	
}	
